export GOPROXY=https://athens.azurefd.net
#export GOPROXY=https://goproxy.io
default: build

build: export GO111MODULE=on
build: gen_sp gen_sproto cmd_bin

# 编译服务器
cmd_bin:
ifeq ("$(WITH_RACE)", "1")
	CGO_ENABLED=1 go build -race -o bin/serve.exe main.go
else
	CGO_ENABLED=0 go build -o bin/serve.exe main.go
endif


# 编译Linux平台的服务器
build_linux:
ifeq ("$(WITH_RACE)", "1")
	GOOS=linux CGO_ENABLED=1 go build -race -o bin/server-linux main.go
else
	GOOS=linux CGO_ENABLED=0 go build -o bin/server-linux main.go
endif

debug:
ifeq ("$(WITH_RACE)", "1")
	CGO_ENABLED=1 go build -race -o bin/debug-server main.go
else
	CGO_ENABLED=0 go build -o bin/debug-server main.go
endif

# 编译生成协议文件程序
gen_sp:
ifeq ("$(WITH_RACE)", "1")
	CGO_ENABLED=1 go build -race -o Protocol/gen_sp Protocol/protocol/sproto/gen_sp/main.go
else
	CGO_ENABLED=0 go build -o Protocol/gen_sp Protocol/protocol/sproto/gen_sp/main.go
endif


# 生成协议文件
gen_sproto:
	Protocol/gen_sp Protocol/proto/logic.sproto > sp/sp.go
	@echo "gofmt"
	@gofmt -l -w -s sp/sp.go

tidy:
	@echo "go mod tidy"
	GO111MODULE=on go mod tidy

clean:
	rm -rf bin/*